package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.FileService;
import com.atguigu.spzx.model.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Tag(name = "文件管理模块")
@RequestMapping("/admin/system/file")
public class FileController {
    @Resource
    FileService fileService;
    //文件上传保存到桶内的哪个目录下 ，文件流
    @Operation(summary = "文件上传接口")
    @PostMapping("upload/{module}")
    public Result upload(@PathVariable("module") String module ,
                         MultipartFile file){//只能接受name属性值为file的上传表单项
        String path = fileService.upload(module,file);
        //返回上传成功的文件的地址
        return Result.ok(path);
    }



    @Operation(summary = "文件删除接口")
    @DeleteMapping("delete")
    public Result delete(String path){
        fileService.delete(path);
        //返回上传成功的文件的地址
        return Result.ok();
    }
}
